package com.itheima.mapper1;

import com.itheima.domain.Address;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

/**
 * @author wuyiqiang
 * @2022/6/19 15:32
 */
@Mapper
public interface AddressMapper {

    /**
     * 获取默认收货地址
     *
     * @return
     */
    @Select("select * from address where is_default=1")
    Address getAddress();

    /**
     * 修改默认地址状态
     *
     * @param address
     * @return
     */
    @Update("update address set is_default=#{isDefault} where id=#{id}")
    void setAddress(Address address);

    /**
     * 根据id查询地址
     *
     * @param id
     * @return
     */
    @Select("select * from address where id=#{id}")
    Address selectById(String id);

    /**
     * 查询地址列表
     *
     * @return
     */
    @Select("select * from address")
    List<Address> selectAll();

    /**
     * 新增收货地址
     *
     * @param address
     * @return
     */
    @Insert("insert into address (id,user_id,consignee,phone,sex,detail,label,create_user)" +
            "values (#{id},#{userId},#{consignee},#{phone},#{sex},#{detail},#{label},#{createUser})")
    void add(Address address);

    /**
     * 删除收货地址
     * @param ids
     */
    @Delete("delete from address where id=#{ids}")
    void delete(String ids);

    /**
     * 修改收货地址
     * @param address
     */
    void update(Address address);
}
